package src.com.java.dtgh.twoDay;

import java.util.Scanner;

public class demo1 {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int space = sc.nextInt();

        int[] weight = new int[n];
        int[] value = new int[n];
        for (int i = 0; i < n; i++) {
            weight[i] = sc.nextInt();
        }
        for (int i = 0; i < n; i++) {
            value[i] = sc.nextInt();
        }
        int[][] solve = solve(weight, value, space);
        System.out.println(solve[n - 1][space]);

    }

    public static int[][] solve(int[] weight,int[] value,int space){

        int len = weight.length;
        int[][] dp = new int[len][space + 1];

        for(int j = weight[0];j <= space;j++){
            dp[0][j] = weight[0];
        }
        for(int i = 0;i < len;i++){
            dp[i][0] = 0;
        }
        for(int i = 1;i < len;i++){
            for(int j = 1;j <= space;j++){

                if(j < weight[i]){
                    dp[i][j] = dp[i-1][j];
                }else {
                    dp[i][j] = Math.max(dp[i - 1][j],dp[i -1][j - weight[i]] + value[i]);
                }
            }
        }
        return dp;
    }
}
